<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>微信自定义菜单管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#name").focus();
			$("#keywords").val('${wechatMenu.keywords}');
			$("input[name='type'][value='${wechatMenu.type}']").attr("checked",true); 
			hideDiv('${wechatMenu.type}'); 		//默认外链
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		
		function hideDiv(v){
			if(v != null){
				if(v === 'click'){
					$('#url_id').hide();
					$('#key_id').show();
				}else if(v === 'view'){
					$('#url_id').show();
					$('#key_id').hide();
				}else if(v === 'scancode_push'){
					$('#key_id').hide();
					$('#url_id').hide();
				}else if(v === 'scancode_waitmsg'){
					$('#key_id').hide();
					$('#url_id').hide();
				}
					
			}
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/wechat/wechatMenu/">菜单列表</a></li>
		<li <c:if test="${sub ne '1' }">class="active"</c:if>><a href="${ctx}/wechat/wechatMenu/form?id=${wechatMenu.id}">主菜单<shiro:hasPermission name="wechat:wechatMenu:edit">${not empty wechatMenu.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="wechat:wechatMenu:edit">查看</shiro:lacksPermission></a></li>
		<li <c:if test="${sub eq '1' }">class="active"</c:if>><a href="${ctx}/wechat/wechatMenu/form?id=${wechatMenu.id}&sub=1">子菜单<shiro:hasPermission name="wechat:wechatMenu:edit">${not empty wechatMenu.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="wechat:wechatMenu:edit">查看</shiro:lacksPermission></a></li>
	</ul>
	<form:form id="inputForm" modelAttribute="wechatMenu"  action="${ctx}/wechat/wechatMenu/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<form:hidden path="user.id"/>
		<form:hidden path="eventKey"/>
		
		
		<c:if test="${sub ne '1' }">
			<form:hidden path="parent.id" value="0"/>
			<form:hidden path="level" value="0"/>
		</c:if>
		<tags:message content="${message}"/>
		
		<c:if test="${sub eq '1' }">
		<form:hidden path="level" value="1"/>
		<div class="control-group">
			<label class="control-label">主菜单:</label>
			<div class="controls">
				<form:select path="parent.id" items="${mainMenus }" itemLabel="name" itemValue="id"></form:select>
			</div>
			</div>
		</c:if>
		
		
		<div class="control-group">
			<label class="control-label">名称:</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="11" class="required"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">类型:</label>
			<div class="controls">
				<input type="radio" name="type" value="view" onclick="hideDiv(this.value)" checked="checked"> 外链    &nbsp; 
				<input name="type" type="radio" value="click"  onclick="hideDiv(this.value)"  > 回复内容   &nbsp;
				<input name="type" type="radio" value="scancode_push"  onclick="hideDiv(this.value)"  > 二维码扫描   &nbsp;
				<input name="type" type="radio" value="scancode_waitmsg"  onclick="hideDiv(this.value)"  > 二维码扫描带提示   &nbsp;
				
			</div> 
		</div>
		
		<div class="control-group" id="url_id">
			<label class="control-label">网址:</label>
			<div class="controls">
				<form:input path="url" htmlEscape="false" maxlength="500" class="required"/>
			</div>
		</div>
		
		<div class="control-group" id="key_id">
			<label class="control-label">回复消息:</label>
			<div class="controls">
				<select name="keywords" id="keywords">
						<option value="请选择"></option>
					<c:forEach items="${businessList }" var="keyword">
							<option value="${keyword.name }">${keyword.name }</option>
					</c:forEach>
				</select>
			</div>
		</div>
		
		<div class="control-group" >
			<label class="control-label">排序:</label>
			<div class="controls">
				<form:input path="sort" htmlEscape="false" maxlength="2" class="required"/>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label">备注:</label>
			<div class="controls">
				<form:input path="remarks" htmlEscape="false" maxlength="50"  />
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="wechat:wechatMenu:edit">
			<c:if test="${addFlag eq '1' }"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/></c:if>
			&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>
